/**
 * 创建一个store 函数，专门生产state和dispatch的集合，让别的App可以调用这种模式
 * @param {*} state 
 * @param {*} stateChanger 
 */
export function createStore(reducer) {
    let state = null;
    const listeners = [];
    const getState = () => state;

  

    const subscribe = (listener) => {
        listeners.push(listener);
    }
    const dispatch = (action) => {
        state = reducer(state, action);
        listeners.forEach((listener) => listener())
    }
    dispatch({});
    return {
        getState,
        dispatch,
        subscribe
    }
}